<?php

namespace app\controller;

use app\BaseController;
use Endroid\QrCode\Color\Color;
use Endroid\QrCode\Encoding\Encoding;
use Endroid\QrCode\ErrorCorrectionLevel;
use Endroid\QrCode\QrCode;
use Endroid\QrCode\RoundBlockSizeMode;
use Endroid\QrCode\Writer\PngWriter;

class Index extends BaseController
{
    public function index()
    {
       $url = "https://tfpay.tf.cn/epaygate/wallet/index.html#/confirmPaymentIndex?cGFydG5lcm5vPTEyMDE3ODEwMTYmb3V0bWVtYmVybm89MzdhYzExNDgyZDQyZDFmYzBkMTE4Y2VhNmVmMDBlNDImdHJhbnNhY3Rpb25faWQ9MjAyNDA1MTUxNjE1MDQ4MDAxMjY0MTgyMDEmc2hvd19kZWZhdWx0X3R5cGU9MSZ0cmFuc19jaGFubmVsPW51bGwmdG9rZW49ZGI4ZjYzNGQ4YTIwZjZjYTYzZThjZDdiNTMyZjAxMTMmcmV0dXJuX3VybD1odHRwczovL2FwaXQuaHVpeWxhLmNvbS9hcGkvb3JkZXIvcmV0dXJuX3VybCZzaWduPTVDRTFEM0FEQjg0MzQxNTcwNUJGQUIwQjE5OERBNDI4JnNpZ25fdHlwZT1NRDUmdHJhbnNfc2NlbmU9MQ==";
        $qrCode = QrCode::create($url)
            ->setEncoding(new Encoding('UTF-8'))
            ->setErrorCorrectionLevel(ErrorCorrectionLevel::Low)
            ->setSize(300)
            ->setMargin(10)
            ->setRoundBlockSizeMode(RoundBlockSizeMode::Margin)
            ->setForegroundColor(new Color(0, 0, 0))
            ->setBackgroundColor(new Color(255, 255, 255));
       // header('Content-Type: ' . $qrCode->getContentType());

        $writer = new PngWriter();
        // 生成图片并获取其内容
        $result = $writer->write($qrCode, null, null);
        header('Content-Type: '.$result->getMimeType());
        //echo $result->getString();
        // 输出Base64编码的字符串
      //  $result->saveToFile(__DIR__.'/qrcode.png');

        $dataUri = $result->getDataUri();
        dump($dataUri);exit;
    }

    public function hello($name = 'ThinkPHP8')
    {
        return 'hello,' . $name;
    }
}
